﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PrototypeZGame
{
    public class Inventory
    {
        private List<InventoryItem> _items;

        public List<InventoryItem> items
        {
            get
            {
                return _items;
            }
        }


        public InventoryItem rightHand;


        private World world;

        private int _capacity;
        public int capacity
        {
            get
            {
                return _capacity;
            }
        }

        public int freeSpace
        {
            get
            {
                return _capacity - _items.Count;
            }
        }
        public int Count
        {
            get
            {
                return _items.Count;
            }
        }

        public Inventory(World world, int capacity)
        {
            this.world = world;
            _capacity = capacity;
            _items = new List<InventoryItem>(capacity);
            rightHand = null;
        }

        public bool putIn(InventoryItem item)
        {
            item.inUse = false;
            if (_items.Count < capacity)
            {
                _items.Add(item);
                return true;
            }
            else
            {
                return false;
            }
        }

        public InventoryItem takeFrom(int num)
        {
            InventoryItem ret = _items[num];
            if (ret.inUse)
            {
                rightHand = null;
                ret.inUse = false;
            }
            _items.RemoveAt(num);
            return ret;
        }

        public InventoryItem at(int num)
        {
            return _items[num];
        }

        public void wear(int num)
        {
            InventoryItem item = _items[num];
            Weapon weapon = item as Weapon;
            if (weapon != null)
            {
                if (rightHand != null)
                {
                    rightHand.inUse = false;
                }

                rightHand = item;
                rightHand.inUse = true;
                return;
            }


        }


    }
}
